package com.mmd.manage.web;


import com.mmd.bean.CODE;
import com.mmd.bean.WebJsonBean;
import com.mmd.manage.service.CommonService;
import com.mmd.manage.service.PostCodeService;
import com.mmd.manage.service.RouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping(value = "/api/common")
@Controller
public class CommonController {

    @Autowired
    private RouteService routeService;
    @Autowired
    private PostCodeService postCodeService;
    @Autowired
    private CommonService commonService;

    @RequestMapping(value = "/getModeList")
    @ResponseBody
    public WebJsonBean getModeList() {
        return new WebJsonBean(CODE.SUCCESS, routeService.getModeList());
    }

    @RequestMapping(value = "/getAreaList")
    @ResponseBody
    public WebJsonBean getAreaList(Long parentAreaId) {
        parentAreaId = parentAreaId == null ? 0 : parentAreaId;
        return new WebJsonBean(CODE.SUCCESS, routeService.getAreaList(parentAreaId));
    }

    @RequestMapping(value = "/getSonAreaList")
    @ResponseBody
    public WebJsonBean getSonAreaList(Long parentAreaId) {
        parentAreaId = parentAreaId == null ? 0 : parentAreaId;
        return new WebJsonBean(CODE.SUCCESS, routeService.getSonAreaList(parentAreaId));
    }

    @RequestMapping(value = "/getHscodeList")
    @ResponseBody
    public WebJsonBean getHscodeList(String hscodename, String quotationNo) {
        return new WebJsonBean(CODE.SUCCESS, routeService.getHscodeList(hscodename, quotationNo));
    }

    @RequestMapping(value = "/getFbaByAreaId")
    @ResponseBody
    public WebJsonBean getFbaByAreaId(Long areaId) {
        return new WebJsonBean(CODE.SUCCESS, routeService.getFbaByAreaId(areaId));
    }

    @RequestMapping(value = "/getPostcodeList")
    @ResponseBody
    public WebJsonBean getPostcodeList(Long areaId) {
        return new WebJsonBean(CODE.SUCCESS, postCodeService.getPostcodeList(areaId));
    }


    /**
     * 获取提单号的物流轨迹
     *
     * @return
     */
    @RequestMapping(value = "/getDeliveryTrackList")
    @ResponseBody
    public WebJsonBean getDeliveryTrackList() {
        return new WebJsonBean(CODE.SUCCESS, commonService.getDeliveryTrackList());
    }
}
